import router from './router'
import { userStore } from '@/pinia/modules/user'
import { getUrlParams } from "@/utils/public";
let getgetActInfoSet = false
router.beforeEach( async (to, from) => {
  const useUserStore = userStore();
  let {
    user_id = getUrlParams("user_id") || useUserStore.user_id,
  } = to.query
  if(!user_id && to.path!='/404') {
    return {
      path:'/404'
    }
  }
  if(to.name == 'Home' && getgetActInfoSet == false) {
    getgetActInfoSet = true
    useUserStore.user_id = user_id;
    await useUserStore.getWallet()
    await useUserStore.getActInfo()
  }
  return true
})

router.afterEach((to) => {
  document.title = to.meta.title as string;
})
